/**
 * CatalogController.java 15 mai 2006
 * 
 * Copyright (c) 2006 Emmanuel PUYBARET / eTeks <info@eteks.com>. All Rights
 * Reserved.
 * 
 * This program is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation; either version 2 of the License, or (at your option) any later
 * version.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 * 
 * You should have received a copy of the GNU General Public License along with
 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
 * Place, Suite 330, Boston, MA 02111-1307 USA
 */
package org.windu2b.jcaddie.swing;

import java.util.*;

import javax.swing.*;
import javax.swing.undo.*;

import org.windu2b.jcaddie.model.*;

/**
 * A MVC controller for the product catalog.
 * 
 * @author Emmanuel Puybaret, windu.2b
 * 
 */
public class CatalogController
{
	private Catalog	   catalog;


	private JComponent	catalogView;


	private UserPreferences preferences;


	private UndoableEditSupport undoSupport;
	
	
	
	/**
	 * Creates a controller of the product catalog view.
	 * 
	 * @param catalog
	 *            the product catalog of the application
	 */
	public CatalogController( Catalog catalog, UserPreferences preferences, UndoableEditSupport undoSupport )
	{
		this.catalog = catalog;
		this.preferences = preferences;
		this.undoSupport = undoSupport;
		this.catalogView = new CatalogTree( catalog, this );
	}




	/**
	 * Returns the view associated with this controller.
	 */
	public JComponent getView()
	{
		return catalogView;
	}




	/**
	 * Updates the selected product in catalog.
	 */
	public void setSelectedProduct( List<CatalogPieceOfProduct> selectedProduct )
	{
		catalog.setSelectedProduct( selectedProduct );
	}
	
	
	
	/**
	 * Controls the modification of selected product.
	 */
	public void modifySelectedCategory()
	{
		if ( !Catalog.getProductSubList( catalog.getSelectedProduct() ).isEmpty() )
		{
			new CatalogPieceOfProductController( catalog.getSelectedProduct().get( 0 ), preferences, this.undoSupport );
		}
	}
}
